home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / xml4j.jar / com / ibm / xml / dom / DocumentImpl.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-08-30  |  6.7 KB  |  330 lines

  1. package com.ibm.xml.dom;
  2.  
  3. import java.util.Enumeration;
  4. import java.util.Hashtable;
  5. import org.w3c.dom.Attr;
  6. import org.w3c.dom.CDATASection;
  7. import org.w3c.dom.Comment;
  8. import org.w3c.dom.DOMException;
  9. import org.w3c.dom.DOMImplementation;
  10. import org.w3c.dom.Document;
  11. import org.w3c.dom.DocumentFragment;
  12. import org.w3c.dom.DocumentType;
  13. import org.w3c.dom.Element;
  14. import org.w3c.dom.Entity;
  15. import org.w3c.dom.EntityReference;
  16. import org.w3c.dom.NamedNodeMap;
  17. import org.w3c.dom.Node;
  18. import org.w3c.dom.NodeList;
  19. import org.w3c.dom.Notation;
  20. import org.w3c.dom.ProcessingInstruction;
  21. import org.w3c.dom.Text;
  22.  
  23. public class DocumentImpl extends NodeImpl implements Document {
  24.    static final long serialVersionUID = 515687835542616694L;
  25.    protected DocumentTypeImpl docType;
  26.    protected ElementImpl docElement;
  27.    protected Hashtable identifiers;
  28.  
  29.    public DocumentImpl() {
  30.       super((DocumentImpl)null, (String)null, (String)null);
  31.       super.ownerDocument = this;
  32.    }
  33.  
  34.    public short getNodeType() {
  35.       return 9;
  36.    }
  37.  
  38.    public String getNodeName() {
  39.       return "#document";
  40.    }
  41.  
  42.    public String getNodeValue() {
  43.       return null;
  44.    }
  45.  
  46.    public Node cloneNode(boolean var1) {
  47.       DocumentImpl var2 = new DocumentImpl();
  48.       if (var1) {
  49.          for(NodeImpl var3 = (NodeImpl)((NodeImpl)this).getFirstChild(); var3 != null; var3 = var3.nextSibling) {
  50.             ((NodeImpl)var2).appendChild(var2.importNode(var3, true));
  51.          }
  52.       }
  53.  
  54.       return var2;
  55.    }
  56.  
  57.    public Node insertBefore(Node var1, Node var2) throws DOMException {
  58.       short var3 = var1.getNodeType();
  59.       if ((var3 != 1 || this.docElement == null) && (var3 != 10 || this.docType == null)) {
  60.          super.insertBefore(var1, var2);
  61.          if (var3 == 1) {
  62.             this.docElement = (ElementImpl)var1;
  63.          } else if (var3 == 10) {
  64.             this.docType = (DocumentTypeImpl)var1;
  65.          }
  66.  
  67.          return var1;
  68.       } else {
  69.          throw new DOMExceptionImpl((short)3, (String)null);
  70.       }
  71.    }
  72.  
  73.    public Node removeChild(Node var1) throws DOMException {
  74.       super.removeChild(var1);
  75.       short var2 = var1.getNodeType();
  76.       if (var2 == 1) {
  77.          this.docElement = null;
  78.       } else if (var2 == 10) {
  79.          this.docType = null;
  80.       }
  81.  
  82.       return var1;
  83.    }
  84.  
  85.    public void setNodeValue(String var1) throws DOMException {
  86.       throw new DOMExceptionImpl((short)7, (String)null);
  87.    }
  88.  
  89.    public Attr createAttribute(String var1) throws DOMException {
  90.       if (!isXMLName(var1)) {
  91.          throw new DOMExceptionImpl((short)5, (String)null);
  92.       } else {
  93.          return new AttrImpl(this, var1);
  94.       }
  95.    }
  96.  
  97.    public CDATASection createCDATASection(String var1) throws DOMException {
  98.       return new CDATASectionImpl(this, var1);
  99.    }
  100.  
  101.    public Comment createComment(String var1) {
  102.       return new CommentImpl(this, var1);
  103.    }
  104.  
  105.    public DocumentFragment createDocumentFragment() {
  106.       return new DocumentFragmentImpl(this);
  107.    }
  108.  
  109.    public Element createElement(String var1) throws DOMException {
  110.       if (!isXMLName(var1)) {
  111.          throw new DOMExceptionImpl((short)5, (String)null);
  112.       } else {
  113.          return new ElementImpl(this, var1);
  114.       }
  115.    }
  116.  
  117.    public EntityReference createEntityReference(String var1) throws DOMException {
  118.       if (!isXMLName(var1)) {
  119.          throw new DOMExceptionImpl((short)5, (String)null);
  120.       } else {
  121.          return new EntityReferenceImpl(this, var1);
  122.       }
  123.    }
  124.  
  125.    public ProcessingInstruction createProcessingInstruction(String var1, String var2) throws DOMException {
  126.       if (!isXMLName(var1)) {
  127.          throw new DOMExceptionImpl((short)5, (String)null);
  128.       } else {
  129.          return new ProcessingInstructionImpl(this, var1, var2);
  130.       }
  131.    }
  132.  
  133.    public Text createTextNode(String var1) {
  134.       return new TextImpl(this, var1);
  135.    }
  136.  
  137.    public DocumentType getDoctype() {
  138.       if (super.syncChildren) {
  139.          ((NodeImpl)this).synchronizeChildren();
  140.       }
  141.  
  142.       return this.docType;
  143.    }
  144.  
  145.    public Element getDocumentElement() {
  146.       if (super.syncChildren) {
  147.          ((NodeImpl)this).synchronizeChildren();
  148.       }
  149.  
  150.       return this.docElement;
  151.    }
  152.  
  153.    public NodeList getElementsByTagName(String var1) {
  154.       return new DeepNodeListImpl(this, var1);
  155.    }
  156.  
  157.    public DOMImplementation getImplementation() {
  158.       return DOMImplementationImpl.singleton;
  159.    }
  160.  
  161.    public DocumentType createDocumentType(String var1) throws DOMException {
  162.       if (!isXMLName(var1)) {
  163.          throw new DOMExceptionImpl((short)5, (String)null);
  164.       } else {
  165.          return new DocumentTypeImpl(this, var1);
  166.       }
  167.    }
  168.  
  169.    public Entity createEntity(String var1) throws DOMException {
  170.       return new EntityImpl(this, var1);
  171.    }
  172.  
  173.    public Notation createNotation(String var1) throws DOMException {
  174.       return new NotationImpl(this, var1);
  175.    }
  176.  
  177.    public ElementDefinitionImpl createElementDefinition(String var1) throws DOMException {
  178.       return new ElementDefinitionImpl(this, var1);
  179.    }
  180.  
  181.    public Node importNode(Node var1, boolean var2) throws DOMException {
  182.       Object var3 = null;
  183.       short var4 = var1.getNodeType();
  184.       switch (var4) {
  185.          case 1:
  186.             Element var12 = this.createElement(var1.getNodeName());
  187.             NamedNodeMap var17 = var1.getAttributes();
  188.             if (var17 != null) {
  189.                for(int var19 = 0; var19 < var17.getLength(); ++var19) {
  190.                   var12.setAttributeNode((AttrImpl)this.importNode(var17.item(var19), true));
  191.                }
  192.             }
  193.  
  194.             var3 = (NodeImpl)var12;
  195.             break;
  196.          case 2:
  197.             var3 = (NodeImpl)this.createAttribute(var1.getNodeName());
  198.             break;
  199.          case 3:
  200.             var3 = (NodeImpl)this.createTextNode(var1.getNodeValue());
  201.             break;
  202.          case 4:
  203.             var3 = (NodeImpl)this.createCDATASection(var1.getNodeValue());
  204.             break;
  205.          case 5:
  206.             var3 = (NodeImpl)this.createEntityReference(var1.getNodeName());
  207.             var2 = false;
  208.             break;
  209.          case 6:
  210.             Entity var11 = (Entity)var1;
  211.             EntityImpl var16 = (EntityImpl)this.createEntity(var1.getNodeName());
  212.             var16.setPublicId(var11.getPublicId());
  213.             var16.setSystemId(var11.getSystemId());
  214.             var16.setNotationName(var11.getNotationName());
  215.             var3 = var16;
  216.             break;
  217.          case 7:
  218.             var3 = (ProcessingInstructionImpl)this.createProcessingInstruction(var1.getNodeName(), var1.getNodeValue());
  219.             break;
  220.          case 8:
  221.             var3 = (NodeImpl)this.createComment(var1.getNodeValue());
  222.             break;
  223.          case 9:
  224.          default:
  225.             throw new DOMExceptionImpl((short)3, (String)null);
  226.          case 10:
  227.             DocumentTypeImpl var10 = (DocumentTypeImpl)this.createDocumentType(var1.getNodeName());
  228.             NamedNodeMap var14 = ((DocumentType)var1).getEntities();
  229.             NamedNodeMap var7 = var10.getEntities();
  230.             if (var14 != null) {
  231.                for(int var8 = 0; var8 < var14.getLength(); ++var8) {
  232.                   var7.setNamedItem((EntityImpl)this.importNode(var14.item(var8), true));
  233.                }
  234.             }
  235.  
  236.             var14 = ((DocumentType)var1).getNotations();
  237.             var7 = var10.getNotations();
  238.             if (var14 != null) {
  239.                for(int var20 = 0; var20 < var14.getLength(); ++var20) {
  240.                   var7.setNamedItem((NotationImpl)this.importNode(var14.item(var20), true));
  241.                }
  242.             }
  243.  
  244.             var3 = var10;
  245.             break;
  246.          case 11:
  247.             var3 = (NodeImpl)this.createDocumentFragment();
  248.             break;
  249.          case 12:
  250.             Notation var5 = (Notation)var1;
  251.             NotationImpl var6 = (NotationImpl)this.createNotation(var1.getNodeName());
  252.             var6.setPublicId(var5.getPublicId());
  253.             var6.setSystemId(var5.getSystemId());
  254.             var3 = var6;
  255.       }
  256.  
  257.       if (var2) {
  258.          for(Node var13 = var1.getFirstChild(); var13 != null; var13 = var13.getNextSibling()) {
  259.             ((NodeImpl)var3).appendChild(this.importNode(var13, true));
  260.          }
  261.       }
  262.  
  263.       return (Node)var3;
  264.    }
  265.  
  266.    public void putIdentifier(String var1, Element var2) {
  267.       if (var2 == null) {
  268.          this.removeIdentifier(var1);
  269.       }
  270.  
  271.       if (super.syncData) {
  272.          ((NodeImpl)this).synchronizeData();
  273.       }
  274.  
  275.       if (this.identifiers == null) {
  276.          this.identifiers = new Hashtable();
  277.       }
  278.  
  279.       this.identifiers.put(var1, var2);
  280.    }
  281.  
  282.    public Element getIdentifier(String var1) {
  283.       if (super.syncData) {
  284.          ((NodeImpl)this).synchronizeData();
  285.       }
  286.  
  287.       return this.identifiers == null ? null : (Element)this.identifiers.get(var1);
  288.    }
  289.  
  290.    public void removeIdentifier(String var1) {
  291.       if (super.syncData) {
  292.          ((NodeImpl)this).synchronizeData();
  293.       }
  294.  
  295.       if (this.identifiers != null) {
  296.          this.identifiers.remove(var1);
  297.       }
  298.    }
  299.  
  300.    public Enumeration getIdentifiers() {
  301.       if (super.syncData) {
  302.          ((NodeImpl)this).synchronizeData();
  303.       }
  304.  
  305.       if (this.identifiers == null) {
  306.          this.identifiers = new Hashtable();
  307.       }
  308.  
  309.       return this.identifiers.keys();
  310.    }
  311.  
  312.    public static boolean isXMLName(String var0) {
  313.       char[] var1 = new char[var0.length()];
  314.       var0.getChars(0, var0.length(), var1, 0);
  315.       if (!Character.isLetter(var1[0]) && "_:".indexOf(var1[0]) == -1) {
  316.          return false;
  317.       } else {
  318.          for(int var2 = 1; var2 < var0.length(); ++var2) {
  319.             char var3 = var1[var2];
  320.             int var4 = Character.getType(var3);
  321.             if (!Character.isLetterOrDigit(var3) && ".-_:".indexOf(var3) == -1 && (var4 < 6 || var4 > 8 || var3 >= 1757 && var3 <= 1758 || var3 >= 8413 && var3 <= 8416 || var3 >= 12443) && (var4 != 4 || var3 >= 720 && var3 <= 1369 || var3 >= 1765 && var3 <= 1766 || var3 >= 12443 && var3 <= 12444) && var3 != 183 && var3 != 903) {
  322.                return false;
  323.             }
  324.          }
  325.  
  326.          return true;
  327.       }
  328.    }
  329. }
  330.